<%= hidden_field_tag "referrer", params[:referrer] %>

<div id='select_lang' class="langSelect" style="display: block;">
  <% AVAILABLE_LOCALES.each do |locale| %>
  	<%= link_to_function image_tag("manage/flag_#{locale}.gif", :alt=>locale), 
  	      :onclick=>"set_lang('block_#{locale}', this);", 
  	      :class=>(I18n.locale.to_s == locale ? "active" : "") %>
	<% end %>
</div>

<script type='text/javascript'>
  var langs = new Array(<%= AVAILABLE_LOCALES.map(&:inspect).join(',') %>);
  var block = null;
  var links = null;
  
  function set_lang(block, element)
  {
    for(var i = 0; i < langs.length; i++)	{ Element.hide("block_" + langs[i]);}
		Element.show(block);
		
		if (typeof(element) != 'undefined')
		{
		  for(var i = 0; i < links.length; i++)	{ links[i].className = '';}
		  element = $(element);
		  element.className = 'active';
		}
  }
  
	Event.observe(window, 'load', function() 
	{
		set_lang('block_<%= I18n.locale %>');
		block = $('select_lang');
		links = block.select('a');
	});
</script>
